<template>
  <div>
    <el-dialog v-dialogDrag title="新增数据字典" :visible="addShow" width="40%" @close="dialogClose" :close-on-click-modal="false">
      <el-form ref="addForm" :model="formFileds" :rules="rules" label-width="auto">
        <el-form-item label="字典名称：" prop="dictName">
          <el-input type="text" v-model="formFileds.dictName"></el-input>
        </el-form-item>
        <el-form-item label="字典值：" prop="dictValue">
          <el-input type="text" :rows="3" v-model="formFileds.dictValue"></el-input>
        </el-form-item>
        <!-- <el-form-item label="排序：" prop="index">
                    <el-input type="text" v-model="formFileds.index"></el-input>
                </el-form-item> -->
        <!-- <el-form-item label="父级字典：" prop="parentId">
                    <el-input type="text" v-model="formFileds.parentId"></el-input>
                </el-form-item> -->
        <el-form-item>
          <el-button type="primary" @click="submitForm()" class="pull-right margin-l-25">确定
          </el-button>
          <el-button @click="dialogClose" class="pull-right">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { dataDictionaryAdd } from "@/api/systemManage/dataDictionary";
export default {
  //接受父组件
  props: {
    addShow: {
      type: Boolean,
    },
  },

  data () {
    return {
      formFileds: {},
      rules: {
        dictName: [
          {
            required: true,
            message: "请输入字典名称",
            trigger: "blur",
          },
        ],
        dictValue: [
          {
            required: true,
            message: "请输入字典值",
            trigger: "blur",
          },
        ],
        index: [
          {
            required: true,
            message: "请输入排序的值",
            trigger: "blur",
          },
        ],
        // parentId: [{
        //     required: false,
        //     message: '请输入该父级字典',
        //     trigger: 'blur'
        // }],
      },
    };
  },
  methods: {
    dialogClose () {
      this.$emit("dialogClose");
    },
    submitForm () {
      this.$refs.addForm.validate((valid) => {
        if (valid) {
          dataDictionaryAdd(this.formFileds).then((res) => {
            this.$message.success("操作成功");
            this.$emit("dialogClose");
            this.$emit("close");
          });
        } else {
          return;
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>

</style>
